var webpack = require('webpack');
var path = require('path');
var basePath = path.join(__dirname, 'src');
var HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

var webpackConfig = {
  entry: {
    'vendor':    './src/vendor.ts',
    'app':       './src/main.ts',
  },
  output: {
    path:  path.resolve(__dirname, 'dist'),
    filename: '[name].bundle.js'
  },

  resolve: {
    extensions: [ '.ts', '.js'],
    alias: {
      //app: basePath + '/app',
      //shared: basePath + '/app/shared'
    }
  },

  plugins: [
    new webpack.optimize.CommonsChunkPlugin({ name: ['app', 'vendor'], minChunks: Infinity }),
    new HtmlWebpackPlugin({
            template: 'src/index.html'
    }),
    new ExtractTextPlugin({
      filename: '[name].css',
      disable: false,
      allChunks: true,
    }),
    new webpack.ContextReplacementPlugin( /moment[\/\\]locale$/, /en-ca|zh-cn/ ),
  ],

  module: {
    rules: [
      { test: /\.ts$/, use: ['ts-loader', 'angular2-template-loader'] },
      {
          test: /\.html$/,
          use: ['html-loader']
      },{
        test: /\.(css|less)$/,
        //use: ['to-string-loader','css-loader','less-loader'],
        loaders: ['to-string-loader'].concat(ExtractTextPlugin.extract({
            fallback: "style-loader",
            use: ['css-loader',"less-loader"]
        }))
      },
      {
        test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
        use: ['file-loader?name=images/[name].[hash].[ext]']
      },
    ]
  },devServer:{
        historyApiFallback: true,
        hot: true,
        inline: true,
        port: 9090 // 修改端口，一般默认是8080
  }
}

module.exports= webpackConfig;